/**
 * Copyright (c) 2020 QingLang, Inc. <baisui@qlangtech.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package com.qlangtech.tis.solrextend.fieldtype.s4card;

import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import com.qlangtech.tis.solrextend.fieldtype.pinyin.AllWithNGramTokenFilter;

/**
 * @author 百岁（baisui@qlangtech.com）
 * @date 2019年1月17日
 */
public class AllWithPositionNGramTokenFilter extends AllWithNGramTokenFilter {

    private final OffsetAttribute offsetAttribute;

    public AllWithPositionNGramTokenFilter(TokenStream input, int minGram, int maxGram) {
        super(input, minGram, maxGram);
        this.offsetAttribute = this.addAttribute(OffsetAttribute.class);
    }

    @Override
    protected void appendAttribute(char[] curTermBuffer, int curTermLength, int start, int end) {
        this.offsetAttribute.setOffset(start, end);
    }
    // @Override
    // protected void appendAttribute(char[] curTermBuffer, int
    // curTermBufferLength, int start,
    // int end) {
    // 
    // // --113480,5,10
    // // --134,6,8
    // // --1348,6,9
    // // --13480,6,10
    // // --13480
    // 
    // // if (end + 1 > curTermBufferLength) {
    // // System.out.println("xx" + new String(curTermBuffer, start, end -
    // // start + 1) + ","
    // // + start + "," + end);
    // // return;
    // // }
    // //
    // this.offsetAtt.setOffset(start, end);
    // //
    // System.out.println(
    // "--" + new String(curTermBuffer, start, end - start + 1) + "," + start +
    // "," + end);
    // 
    // }
}
